package cn.itcast.com.homework.day825;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by 郭浩 on 2020/8/25 19:46
 * 给定一棵二叉树，判断它是不是镜像对称的。
 *      1
 *     / \
 *   2    2
 * /  \  /  \
 * 3  4 4  3
 */
public class test {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode A1 = new TreeNode(2);
        TreeNode A2 = new TreeNode(2);
        TreeNode B1 = new TreeNode(3);
        TreeNode B2 = new TreeNode(4);
        TreeNode B3 = new TreeNode(4);
        TreeNode B4 = new TreeNode(3);
        root.left = A1;
        root.right = A2;
        A1.left = B1;
        A1.right = B2;
        A2.left = B3;
        A2.right = B4;
        boolean mirror = mirror(root);
        System.out.println(mirror);
    }

    //判断两个点是否时相等的  假如相等，判断这两个相等的点的lr
    public static boolean mirror(TreeNode root){
        if (root == null){
            return true;
        }
        return mmmmm(root.right,root.left);
    }

    private static boolean mmmmm(TreeNode right, TreeNode left) {
        if (right == null && left == null) {
            return true;
        }
        if (right == null || left == null && right.val != left.val){
            return false;
        }
        return mmmmm(right.left,left.right) && mmmmm(left.right, right.left);
    }

}
